#ifndef	__pSystemH__
#define	__pSystemH__

#include"d3dUtility.h"
#include"camera.h"
#include<list>

namespace psys
{
	struct Particle
	{
		D3DXVECTOR3	_position;
		D3DCOLOR	_color;
		static const DWORD FVF;
	};


	struct Attribute
	{
		Attribute()
		{
			_lifeTime = 0.0f;
			_age	  = 0.0f;
			_isAlive  = true;
		}

		D3DXVECTOR3	_position;
		D3DXVECTOR3	_velocity;
		D3DXVECTOR3	_acceleration;
		float		_lifeTime;
		float		_age;
		D3DXCOLOR	_color;
		D3DXCOLOR	_colorFade;
		bool		_isAlive;
	};

	class PSystem
	{
	public:
		PSystem();
		virtual ~PSystem();

		virtual bool init(IDirect3DDevice9* device, wchar_t* texFileName);
		virtual void reset();


		virtual void resetParticle(Attribute* attribute) = 0;
		virtual void addParticle();

		virtual void update(float timeDelta) = 0;

		virtual void preRender();
		virtual void render();
		virtual void postRender();

		bool isEmpty();
		bool isDead();

	protected:
		virtual void removeDeadParticles();

	protected:
		IDirect3DDevice9*			_device;
		D3DXVECTOR3					_origin;
		d3d::BoundingBox			_boudingBox;
		float						_emitRate;
		float						_size;
		IDirect3DTexture9*			_tex;
		IDirect3DVertexBuffer9*		_vb;
		std::list<Attribute>		_particles;
		int							_maxParticles;

		DWORD						_vbSize;
		DWORD						_vbOffset;
		DWORD						_vbBatchSize;
	};


}


#endif //__pSystemH__